package 算法.抽奖算法;

import utils.BaseUtil;
import 算法.抽奖算法.base.LotteryTurnTableEnum;

import java.util.Random;

/**
 * @author yangjicong
 * @date 2022/2/20
 */
public class RunRandomDrawing {

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {

            randomLottery();
        }

    }

    /**
     * 根据概率生成转盘抽奖名称及数额(有需求可以将概率丢到配置里)
     * 一等奖，400元，概率0.5%
     * 二等奖，299元，概率1%
     * 三等奖，199元，概率3%
     * 幸运奖，0.01-399元随机金额，概率25.5%
     * 谢谢参与，0元，概率70%
     * @return
     */
    public static void randomLottery(){
//        LotteryTurntableBO lotteryTurntableBO = new LotteryTurntableBO();
        long maxElement = 100;
        Random random = new Random();
        double LotteryTurntableNum = random.nextDouble() * maxElement;
        String LotteryTurntableName = LotteryTurnTableEnum.LOTTERY_THANKS.getCode();
        String lotteryNum = "0.0";
        double probabilityNum = 0.0;
        //一等奖
        if(LotteryTurntableNum>=probabilityNum && LotteryTurntableNum< (Double.parseDouble(LotteryTurnTableEnum.LOTTERY_ONE.getDesc()) + probabilityNum) ){
            LotteryTurntableName = LotteryTurnTableEnum.LOTTERY_ONE.getCode();
            lotteryNum = LotteryTurnTableEnum.LOTTERY_ONE.getMark();
            System.out.println(LotteryTurnTableEnum.LOTTERY_ONE.getCode());
        }
        probabilityNum += Double.parseDouble(LotteryTurnTableEnum.LOTTERY_ONE.getDesc());
        //二等奖
        if(LotteryTurntableNum>=probabilityNum && LotteryTurntableNum < (Double.parseDouble(LotteryTurnTableEnum.LOTTERY_TWO.getDesc()) + probabilityNum) ){
            LotteryTurntableName = LotteryTurnTableEnum.LOTTERY_TWO.getCode();
            lotteryNum = LotteryTurnTableEnum.LOTTERY_TWO.getMark();
            System.out.println(LotteryTurnTableEnum.LOTTERY_TWO.getCode());
        }
        probabilityNum += Double.parseDouble(LotteryTurnTableEnum.LOTTERY_TWO.getDesc());
        //三等奖
        if(LotteryTurntableNum>=probabilityNum && LotteryTurntableNum < (Double.parseDouble(LotteryTurnTableEnum.LOTTERY_THREE.getDesc())+ probabilityNum) ){
            LotteryTurntableName = LotteryTurnTableEnum.LOTTERY_THREE.getCode();
            lotteryNum = LotteryTurnTableEnum.LOTTERY_THREE.getMark();
            System.out.println(LotteryTurnTableEnum.LOTTERY_THREE.getCode());
        }
        probabilityNum += Double.parseDouble(LotteryTurnTableEnum.LOTTERY_THREE.getDesc());
        //幸运奖
        if(LotteryTurntableNum>=probabilityNum && LotteryTurntableNum< (Double.parseDouble(LotteryTurnTableEnum.LOTTERY_LUCKY.getDesc())+ probabilityNum) ){
            LotteryTurntableName = LotteryTurnTableEnum.LOTTERY_LUCKY.getCode();
            //打印
            System.out.println(LotteryTurnTableEnum.LOTTERY_LUCKY.getCode());
            //幸运奖金额需要另外做随机
            long maxNum = 399;
            double num;
            do {
                num = random.nextDouble() * maxNum;
            }while (num == 0.0);
            lotteryNum = String.valueOf(BaseUtil.keepTwoDecimal(num));
        }
        probabilityNum += Double.parseDouble(LotteryTurnTableEnum.LOTTERY_LUCKY.getDesc());
        //谢谢参与
        if(LotteryTurntableNum>=probabilityNum && LotteryTurntableNum< (Double.parseDouble(LotteryTurnTableEnum.LOTTERY_THANKS.getDesc())+ probabilityNum) ){
            LotteryTurntableName = LotteryTurnTableEnum.LOTTERY_THANKS.getCode();
            lotteryNum = LotteryTurnTableEnum.LOTTERY_THANKS.getMark();
            System.out.println(LotteryTurnTableEnum.LOTTERY_THANKS.getCode());
        }
//        lotteryTurntableBO.setLotteryName(LotteryTurntableName);
//        lotteryTurntableBO.setLotteryNum(String.valueOf(BaseUtil.getElementByCent(lotteryNum)));
//        return lotteryTurntableBO;
    }

}
